package pattern_observer;

import java.util.ArrayList;
import java.util.List;

public final class MailBox implements Observable {
	
	private int numberOfMessage;
	private boolean notEmpty = false;
	private static MailBox mx = null;
	private String message = "";
	private String iD = "MailBox";
	
	private List<Observer> listObserver;
	
	@Override
	public void prevenir() {
		for (Observer obs : listObserver) {
			System.out.println("Mailbox : " + "un message a ete ecrit.");
			obs.notifier(this);
		}
	}
	
	@Override
	public String description() {
		return iD;
	}

	@Override
	public void inscrire(Observer obs) {
		listObserver.add(obs);
	}
	
	@Override
	public void desinscrire(Observer obs) {
		listObserver.remove(obs);
	}
	
	private MailBox() {
		listObserver = new ArrayList<Observer>();
	}
	
	public static MailBox getMailBox() {
		if (mx == null) {
			mx = new MailBox();
		} 
		return mx;
	}
	
	public int getNumberOfMessage() {
		return numberOfMessage;
	}
	
	public boolean isEmpty() {
		return !notEmpty;
	}
	
	public void ecrire(String message) {
		this.message = message;
		prevenir();
	}
	
	public String getMessage() {
		return message;
	}
}
